/*
 * @Author: Zhang Yingying
 * @Date: 2020-11-02 14:21:04
 * @LastEditors: Zhang Yingying
 * @LastEditTime: 2020-12-09 22:27:33
 */

import store from "@/store";
import router from "@/router";

router.beforeResolve((to, from, next) => {
  const loginUser = store.state.user.user;
  // 判断路由是否设置相应校验用户权限
  if (to.meta.requireAuth) {
    if (!loginUser) {
      // 没有登录，显示登录组件
      store.dispatch("setShowLogin", true);
      if (from.name == null) {
        //此时，是在页面没有加载，直接在地址栏输入链接，进入需要登录验证的页面
        next("/");
        return;
      }
      // 终止导航
      next(false);
      return;
    }
  }
  next();
});
